<?php

if( !defined("IN_ELCIUS") ) exit;


class KiwiRequest{
	
	public static $Data; // TODO: add to $PageData somewhere
	
	private static $initalized = false;
	
	private static $selectedSkin;
	private static $requestedContent;
	
	public static function Initialize(){
		self::$selectedSkin = 'Default'; // TODO: confirm existance
		self::$Data['UserSkin'] = self::$selectedSkin;
		self::$initalized = true;
	}
	
	public static function Process(){
		global $Settings;
		
		if( !self::$initalized ) return false;
		
		self::$requestedContent = strtolower( Clean( GetRequestVar('page'), 'a-zA-Z0-9_-' ) );
		
		if( !isset( $Settings['Content'][ self::$requestedContent ] ) ){
			self::$requestedContent = 'home';
		}
		
		self::$Data['ContentName'] = self::$requestedContent;
		
	}
	
	public static function GetPageTemplate(){
		
		if( !self::$initalized ) return false;
		
		if( file_exists('./skins/'.self::$selectedSkin.'/page.html') ){ // TODO: *file include
			return file_get_contents('./skins/'.self::$selectedSkin.'/page.html');
		}
		return null;
	}
	
	public static function GetContentTemplate(){
		
		if( !self::$initalized ) return false;
		if( !isset( self::$requestedContent ) ) return false;
		if( file_exists('./skins/'.self::$selectedSkin.'/templates/'.self::$requestedContent.'.html') ){ // TODO: *read file
			return file_get_contents('./skins/'.self::$selectedSkin.'/templates/'.self::$requestedContent.'.html');
		}
		
	}
	
	public static function IncludeContent(){
		global $Settings,$PageData,$WowArmory; // TODO: is wowarmory secure enough to give to content files?
		
		if( !self::$initalized ) return false;
		if( !isset( self::$requestedContent ) ) return false;
		
		if( file_exists('./content/'.self::$requestedContent.'.php') ){ // TODO: *file include
			include('./content/'.self::$requestedContent.'.php');
		}
		
	}
	
	public static function IncludeWidgets(){ // TODO
		global $Settings,$PageData,$WowArmory; // TODO: is wowarmory secure enough to give to widgets?
		
		if( !self::$initalized ) return false;
		if( !isset( $Settings['Widgets'] ) or !is_array( $Settings['Widgets'] ) ) return false;
		
		foreach( $Settings['Widgets'] as $widget => $enabled ){
			$widget = Clean($widget,'a-zA-Z0-9_');
			if( $enabled and file_exists('./widgets/'.$widget.'.php') ){
				include('./widgets/'.$widget.'.php');
			}
		}
		
	}
	
	public static function IncludeSkinBackend(){
		global $PageData;
		if( !self::$initalized ) return false;
		
		if( file_exists('./skins/'.self::$selectedSkin.'/backend.php') ){ // TODO: *file include
			include('./skins/'.self::$selectedSkin.'/backend.php');
		}
	}
	
	
}

?>